﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Controls;

namespace DB_Test.ServiceReference1
{
    public partial class ProductsClass : IDataErrorInfo
    {
        #region IDataErrorInfo Members

        public string Error
        {
            get { return null; }
        }

        public string this[string columnName]
        {
            get
            {
                string result = string.Empty;
                
                if(columnName == "ProductName")
                {
                    if (string.IsNullOrEmpty(ProductName))
                    {
                        result = "Product name have to be set.";
                    }
                    else
                    {
                        var client = new WCFServiceClient();
                        try
                        {
                            client.Open();
                            bool duplExists = client.GetIfDuplicateProductNamesExists(ProductName);
                            if (duplExists)
                            {
                                result = "Product with current name already exists. Please, select another name.";
                            }
                        }
                        finally
                        {
                            client.Close();
                        }
                    }
                }

                return result;
            }
        }

        #endregion
    }
}
